<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

</body>
<script>
    // 多态: 通过不同类创建的实例化对象,在访问同一个方法,会返回不同的结果!

    // JS  无态,天生就支持多态

    class Cat {
        constructor(name, color) {
            this.name = name;
            this.color = color;
        }
        hall() {
            console.log("喵喵");
        }
    }


    class Dog {
        constructor(name, color) {
            this.name = name;
            this.color = color;
        }
        hall() {
            console.log("旺旺");
        }
    }

    class Pig {
        constructor(name, color) {
            this.name = name;
            this.color = color;
        }
        hall() {
            console.log("哼哼");
        }
    }

    var kitty = new Cat("Kitty", "pink");
    var wang = new Dog("旺财", "black");
    var pei = new Pig("佩奇", "pink");

    function AnimallHall(animal) {
        animal.hall();
    }

    AnimallHall(kitty);
    AnimallHall(wang);
    AnimallHall(pei);
    AnimallHall({
        hall: function () {
            console.log("嘿嘿");
        }
    });

</script>

</html>